package com.ssyt.yt1.day11.basetype;

import java.util.Date;

class Person {

	private String id;
	private String name;
	private int age;

	public Person() {
		super();
	}

	public Person(String id, String name, int age) {
		super();
		this.id = id;
		this.name = name;
		this.age = age;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	/**
	 * 重写Object.equals方法，如果属性内容相等就返回true
	 */
	@Override
	public boolean equals(Object obj) {
		// 同一个对象比较
		if (this == obj) {
			return true;
		}
		if (obj instanceof Person) {
			Person person = (Person) obj;
			if (this.getId().equals(person.getId())
					&& this.getName().equals(person.getName())
					&& this.getAge() == person.getAge()) {
				return true;
			}
		}
		return false;
	}

	// @Override
	// protected void finalize() throws Throwable {
	// System.out.println("对象销毁时调用...");
	// }

}

public class ObjectDemo extends Date {

	/**
	 * toString
	 */
	@Override
	public String toString() {
		return Integer.toHexString(hashCode());
	}

	/**
	 * getClass
	 */
	public void testGetClass() {
		// 当印当前类的全限定名
		System.out.println(getClass().getName());
		System.out.println(super.getClass().getName());
		// 打印父类的名称
		System.out.println(getClass().getSuperclass().getName());

		// 类名输出
		System.out.println(getClass().getSimpleName());
	}

	/**
	 * equals
	 */
	public void testEquals() {
		Person person1 = new Person("50022819999", "张三", 12);
		Person person2 = new Person("500228199991", "张三", 12);
		// 内存地址的比较
		System.out.println(person1 == person2);
		// equals比较，在父类里面默认的是比较内存地址，当然String里面是比较的内容，原因就是String重写了Object.equals方法
		System.out.println(person1.equals(person2));

		// String str1 = new String("50022819999");
		// String str2 = new String("50022819999");
		// System.out.println(str1 == str2);
		// System.out.println(str1.equals(str2));
	}

	public static void main(String[] args) throws Throwable {
		ObjectDemo objectDemo = new ObjectDemo();
		// System.out.println(objectDemo);
		// System.out.println(new ObjectDemo().toString());
		// objectDemo.testGetClass();
		objectDemo.testEquals();
	}
}
